package com.tanhua.server.controller;

import com.tanhua.model.db.Answers;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;
    /*
    * 测灵魂-问卷列表
    *  GET /testSou
    * */
    @GetMapping("/testSoul")
    public ResponseEntity testSoul(){
        List<QuestionnaireVo> vo = testSoulService.testSoul();
        return ResponseEntity.ok(vo);
    }
    /*
    * 测灵魂-提交问卷
    * POST/testSoul
    * */
    @PostMapping("/testSoul")
    public ResponseEntity commit(@RequestBody Map map){
        List<Answers> answers = (List) map.get("answers");
        String vo = testSoulService.commit(answers);
        return ResponseEntity.ok(vo);
    }
    /*
     * 测灵魂-查看结果
     * GET/testSoul/report/:id
     * */
    @GetMapping("/testSoul/report/{id}")
    public ResponseEntity getReport(@PathVariable("id") Long id){
        ReportVo vo = testSoulService.getReport(id);
        return ResponseEntity.ok(vo);
    }
}
